Intro

Supabase Connect

This is a collection of unstyled components that make it easy to connect your Nordcraft project to Supabase. You can see it in action here in the Nordbase template.

Components

  • supa-auth-callback-handler

    Handles the OAuth callback from Supabase using the PKCE flow. Extracts the authorization code from the URL, exchanges it for access and refresh tokens, and stores them in secure HttpOnly cookies.

    Attributes

    anon-keySupabase anonymous API key used for authenticating the request.
    project-urlThe base URL of the Supabase project used to construct the API endpoint.

    Events

    onErrorThis event is triggered if an error occurs during the sign-in or cookie process.
    onSuccessThis event is triggered once the authentication and cookie setting processes are successfully completed.
  • supa-change-pw-form

    Form component to handle password change via Supabase. Submits the new password using a secured API call and handles success and error outcomes.

    Attributes

    anon-keySupabase anonymous API key used in request headers.
    project-urlBase URL of the Supabase project for making the API call.

    Events

    onErrorTriggered when the password change request fails.
    onSuccessTriggered when the password change request completes successfully.
    onSubmitTriggered when the user submits the password change form.
  • supa-connect-context

    Provides PKCE-related context data for Supabase OAuth flow, including generation and storage of code verifier and code challenge, as well as helper formulas for redirect and provider link generation. This context must be present at the root level of a page, as some other supa-components subscribe to it for their internal operation.

    Attributes

    project-urlThe base URL of the Supabase project used to construct authentication URLs.
    auth-callback-urlThe redirect URL to be used after authentication.

    Formulas

    refreshTokenExpirationRefresh token expiration in seconds. Used internally to set cookie expiration.
    authProviderLinksReturns a map of available auth providers to their corresponding OAuth login URLs, using the current PKCE code challenge and callback URL.
    codeVerifierReferences the stored PKCE code verifier value. Required internally for the PKCE flow.
    codeChallengeReferences the stored PKCE code challenge value. Required internally for the PKCE flow.
    authCallbackUrlProvides and encodes the auth-callback-url. Used in the OAuth and magic link flows to redirect back after authentication.
  • supa-dropzone

    A drag-and-drop file upload component for Supabase storage. Handles file selection, validation, and uploading via signed URLs.

    Attributes

    acceptSpecifies the accepted file types for upload (e.g., image/*).
    anon-keySupabase anonymous API key used to authenticate the upload requests.
    max-size-mbThe maximum allowed file size in megabytes.
    project-urlBase URL of the Supabase project used for storage API endpoints.
    upload-pathTarget path in the Supabase storage bucket where files should be uploaded.
    allow-multipleWhether multiple files can be selected and uploaded in a single action.

    Events

    onStartTriggered when a file upload process begins.
    onSuccessTriggered when a file is uploaded successfully.
    onErrorTriggered if an error occurs during upload or URL signing.
    onFileTooLargeTriggered when a selected file exceeds the allowed size limit.
    onEndTriggered when the upload process has finished for all files.
    onDropTriggered when files are dropped onto the dropzone.

    Formulas

    labelIdProvides the unique ID for the label element, used by the supa-dropzone-label.
    descriptionIdProvides the unique ID for the description element, used by the supa-dropzone-description.
  • supa-dropzone-description

    Provides a description element for the Supabase dropzone component, connected via ARIA attributes for accessibility.

    Formulas

    descriptionIdID used to bind the dropzone's input to this description element for accessibility. Retrieved from the supa-dropzone context.
  • supa-dropzone-label

    Renders a label element for the Supabase dropzone component and connects it via ARIA attributes for accessibility.

    Formulas

    labelIdID used to bind the dropzone's input to this label element for accessibility. Retrieved from the supa-dropzone context.
  • supa-magic-link-handler

    Handles Supabase magic link authentication by extracting tokens from the URL hash and securely setting them in HttpOnly cookies.

    Events

    onErrorTriggered if an error occurs while parsing the URL or setting the authentication cookies.
    onSuccessTriggered once both access and refresh tokens have been successfully stored as HttpOnly cookies.
  • supa-protected-page-context

    Provides session protection and automatic token refresh logic for pages requiring authenticated Supabase access.

    Attributes

    anon-keySupabase project anonymous key used for API authorization.
    project-urlBase URL of the Supabase project used for API requests.
    redirect-toPath to redirect the user to in case of session refresh failure.
    enable-realtimeFlag to enable or disable Supabase real-time websocket connection.

    Events

    onRefreshErrorTriggered if the session refresh attempt fails.
    onRefreshSuccessTriggered once the session refresh process completes successfully.
    onLogoutErrorTriggered if an error occurs during the logout process.
    onLogoutSuccessTriggered once the logout process completes successfully.

    Formulas

    isRefreshingIndicates whether a session refresh request is currently active.
    userDataCombined object containing user profile information such as ID, email, and timestamps.
    isLoggingOutIndicates whether a logout operation is currently in progress.

    Workflows

    logoutLogs the user out by revoking the refresh token and clearing related cookies.
  • supa-realtime

    Listens to Supabase realtime events (insert, update, delete) on a specific table and triggers events accordingly.

    Attributes

    eventThe type of event to listen for: insert, update, delete.
    tableThe name of the table in Supabase to watch for changes.
    filterOptional filter expression to limit the events received.
    schemaThe schema in which the table resides. Defaults to 'public'.

    Events

    onInsertTriggered when a new row is inserted into the specified table.
    onUpdateTriggered when an existing row is updated in the specified table.
    onDeleteTriggered when a row is deleted from the specified table.
    onErrorTriggered when an error occurs while listening to the realtime feed.
  • supa-refresh-session-handler

    Automatically refreshes a Supabase session using a stored refresh token from HttpOnly cookies and updates the access/refresh tokens if successful.

    Attributes

    anon-keyThe Supabase anonymous API key used to authorize the refresh request.
    project-urlThe base URL of the Supabase project where the refresh token is sent.

    Events

    onErrorTriggered if the session refresh fails or cookies cannot be set properly.
    onSuccessTriggered once new session tokens are successfully fetched and stored.
  • supa-request-pw-form

    Provides a password reset request form using Supabase. Submitting the form triggers the API to send a recovery email.

    Attributes

    anon-keyThe Supabase API key used for authenticating the request.
    project-urlThe base URL of the Supabase project used to send the reset request.
    redirect-toThe URL to which the user should be redirected after clicking the reset link from the email.

    Events

    onSubmitTriggered when the form is submitted before the password reset request is sent.
    onErrorTriggered when the password reset request fails (e.g. due to invalid input or network errors).
    onSuccessTriggered when the password reset request completes successfully.
  • supa-signin-email-pw-form

    A form component that handles user sign-in via email and password for Supabase. On submission, it performs authentication and stores tokens as HttpOnly cookies.

    Attributes

    anon-keyThe Supabase anonymous API key used to authenticate the request.
    project-urlThe Supabase project URL to which the authentication request is sent.

    Events

    onSubmitTriggered when the form is submitted, before the sign-in API request is made.
    onErrorTriggered if the sign-in request fails or cookies cannot be set.
    onSuccessTriggered after successful authentication and token storage.
  • supa-signin-magic-form

    A form component that triggers Supabase magic link authentication. On submission, it requests a magic link for the provided email and optionally creates a user.

    Attributes

    anon-keyThe Supabase anonymous API key used to authenticate the magic link request.
    project-urlThe Supabase project URL used for sending the magic link authentication request.
    create-userIf true, a new user will be created if one does not already exist for the given email.

    Events

    onSubmitTriggered when the form is submitted before sending the magic link request.
    onErrorTriggered if the magic link request fails (e.g. due to network issues or invalid input).
    onSuccessTriggered when the magic link request is successfully sent.
  • supa-signup-email-pw-form

    A form component to handle user sign-up using Supabase with email and password. Sends a request to the Supabase `auth.signup` endpoint.

    Attributes

    anon-keyThe Supabase anonymous API key used to authorize the signup request.
    project-urlThe Supabase project URL used as the base for the signup API call.

    Events

    onSubmitTriggered when the form is submitted, before the signup request is made.
    onErrorTriggered if the signup request fails, e.g. due to an invalid email, weak password, or network issue.
    onSuccessTriggered when the signup request is successfully completed and the user account is created.
  • supa-websocket-context

    A context component that manages a Supabase WebSocket connection, including reconnection logic, heartbeat messaging, and connection state variables. This component is automatically used inside the supa-protected-page-context and should not be used manually.

    Attributes

    enabledBoolean flag to control whether the WebSocket connection should be initialized.
    anon-keyThe Supabase anonymous API key required to authenticate the WebSocket connection.
    project-urlThe base URL of the Supabase project used to construct the WebSocket endpoint.
    access-tokenThe current short-lived access token used to authenticate the WebSocket session.

    Formulas

    accessTokenExposes the current access token from context for use in other formulas or components.
    isConnectedIndicates whether the WebSocket is currently connected.
    isReconnectingIndicates whether a reconnection attempt is currently in progress.